home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  64.0 KB  |  2,549 lines

  1. /* read.c - read a source file -
  2.    Copyright (C) 1986, 1987, 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. #if 0
  21. #define MASK_CHAR (0xFF)    /* If your chars aren't 8 bits, you will
  22.                    change this a bit.  But then, GNU isn't
  23.                    spozed to run on your machine anyway.
  24.                    (RMS is so shortsighted sometimes.)
  25.                    */
  26. #else
  27. #define MASK_CHAR ((int)(unsigned char)-1)
  28. #endif
  29.  
  30.  
  31. /* This is the largest known floating point format (for now). It will
  32.    grow when we do 4361 style flonums. */
  33.  
  34. #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
  35.  
  36. /* Routines that read assembler source text to build spagetti in memory.
  37.    Another group of these functions is in the expr.c module.  */
  38.  
  39. /* for isdigit() */
  40. #include <ctype.h>
  41.  
  42. #include "as.h"
  43. #ifdef BFD_ASSEMBLER
  44. #include "subsegs.h"
  45. #endif
  46.  
  47. #include "obstack.h"
  48. #include "listing.h"
  49.  
  50.  
  51. #ifndef TC_START_LABEL
  52. #define TC_START_LABEL(x,y) (x==':')
  53. #endif
  54.  
  55. /* The NOP_OPCODE is for the alignment fill value.
  56.  * fill it a nop instruction so that the disassembler does not choke
  57.  * on it
  58.  */
  59. #ifndef NOP_OPCODE
  60. #define NOP_OPCODE 0x00
  61. #endif
  62.  
  63. char *input_line_pointer;    /*->next char of source file to parse. */
  64.  
  65. #if BITS_PER_CHAR != 8
  66. /*  The following table is indexed by[(char)] and will break if
  67.     a char does not have exactly 256 states (hopefully 0:255!)!  */
  68. die horribly;
  69. #endif
  70.  
  71. /* used by is_... macros. our ctype[] */
  72. const char lex_type[256] =
  73. {
  74.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    /* @ABCDEFGHIJKLMNO */
  75.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    /* PQRSTUVWXYZ[\]^_ */
  76.   0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,    /* _!"#$%&'()*+,-./ */
  77.   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,    /* 0123456789:;<=>? */
  78.   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,    /* @ABCDEFGHIJKLMNO */
  79.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3,    /* PQRSTUVWXYZ[\]^_ */
  80.   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,    /* `abcdefghijklmno */
  81.   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0,    /* pqrstuvwxyz{|}~. */
  82.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  83.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  84.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  85.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  86.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  87.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  88.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  89. };
  90.  
  91.  
  92. /*
  93.  * In: a character.
  94.  * Out: 1 if this character ends a line.
  95.  */
  96. #define _ (0)
  97. char is_end_of_line[256] =
  98. {
  99. #ifdef CR_EOL
  100.   _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _,    /* @abcdefghijklmno */
  101. #else
  102.   _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _,    /* @abcdefghijklmno */
  103. #endif
  104.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  105.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  106.   _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _,    /* 0123456789:;<=>? */
  107.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  108.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  109.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  110.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  111.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  112.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  113.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  114.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  115.   _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,    /* */
  116. };
  117. #undef _
  118.  
  119. /* Functions private to this file. */
  120.  
  121. static char *buffer;    /* 1st char of each buffer of lines is here. */
  122. static char *buffer_limit;    /*->1 + last char in buffer. */
  123.  
  124. static char *bignum_low;    /* Lowest char of bignum. */
  125. static char *bignum_limit;    /* 1st illegal address of bignum. */
  126. static char *bignum_high;    /* Highest char of bignum. */
  127. /* May point to (bignum_start-1). */
  128. /* Never >= bignum_limit. */
  129.  
  130. int target_big_endian;
  131.  
  132. static char *old_buffer;    /* JF a hack */
  133. static char *old_input;
  134. static char *old_limit;
  135.  
  136. /* Variables for handling include file directory list. */
  137.  
  138. char **include_dirs;    /* List of pointers to directories to
  139.                search for .include's */
  140. int include_dir_count;    /* How many are in the list */
  141. int include_dir_maxlen = 1;/* Length of longest in list */
  142.  
  143. #ifndef WORKING_DOT_WORD
  144. struct broken_word *broken_words;
  145. int new_broken_words;
  146. #endif
  147.  
  148. static char *demand_copy_string PARAMS ((int *lenP));
  149. int is_it_end_of_statement PARAMS ((void));
  150. unsigned int next_char_of_string PARAMS ((void));
  151. static segT get_known_segmented_expression PARAMS ((expressionS * expP));
  152. static void grow_bignum PARAMS ((void));
  153. static void pobegin PARAMS ((void));
  154.  
  155. extern int listing;
  156.  
  157.  
  158. void
  159. read_begin ()
  160. {
  161.   const char *p;
  162.  
  163.   pobegin ();
  164.   obj_read_begin_hook ();
  165.  
  166.   obstack_begin (¬es, 5000);
  167.   obstack_begin (&cond_obstack, 960);
  168.  
  169. #define BIGNUM_BEGIN_SIZE (16)
  170.   bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
  171.   bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
  172.  
  173.   /* Use machine dependent syntax */
  174.   for (p = line_separator_chars; *p; p++)
  175.     is_end_of_line[*p] = 1;
  176.   /* Use more.  FIXME-SOMEDAY. */
  177. }
  178.  
  179. /* set up pseudo-op tables */
  180.  
  181. struct hash_control *po_hash;
  182.  
  183. static const pseudo_typeS potable[] =
  184. {
  185.   {"abort", s_abort, 0},
  186.   {"align", s_align_ptwo, 0},
  187.   {"ascii", stringer, 0},
  188.   {"asciz", stringer, 1},
  189. /* block */
  190.   {"byte", cons, 1},
  191.   {"comm", s_comm, 0},
  192.   {"data", s_data, 0},
  193. /* dim */
  194.   {"double", float_cons, 'd'},
  195. /* dsect */
  196.   {"eject", listing_eject, 0},    /* Formfeed listing */
  197.   {"else", s_else, 0},
  198.   {"end", s_end, 0},
  199.   {"endif", s_endif, 0},
  200. /* endef */
  201.   {"equ", s_set, 0},
  202. /* err */
  203. /* extend */
  204.   {"extern", s_ignore, 0},    /* We treat all undef as ext */
  205.   {"appfile", s_app_file, 0},
  206.   {"file", s_app_file, 0},
  207.   {"fill", s_fill, 0},
  208.   {"float", float_cons, 'f'},
  209.   {"global", s_globl, 0},
  210.   {"globl", s_globl, 0},
  211.   {"hword", cons, 2},
  212.   {"if", s_if, 0},
  213.   {"ifdef", s_ifdef, 0},
  214.   {"ifeqs", s_ifeqs, 0},
  215.   {"ifndef", s_ifdef, 1},
  216.   {"ifnes", s_ifeqs, 1},
  217.   {"ifnotdef", s_ifdef, 1},
  218.   {"include", s_include, 0},
  219.   {"int", cons, 4},
  220.   {"lcomm", s_lcomm, 0},
  221.   {"lflags", listing_flags, 0},    /* Listing flags */
  222.   {"list", listing_list, 1},    /* Turn listing on */
  223.   {"long", cons, 4},
  224.   {"lsym", s_lsym, 0},
  225.   {"nolist", listing_list, 0},    /* Turn listing off */
  226.   {"octa", big_cons, 16},
  227.   {"org", s_org, 0},
  228.   {"psize", listing_psize, 0},    /* set paper size */
  229. /* print */
  230.   {"quad", big_cons, 8},
  231.   {"sbttl", listing_title, 1},    /* Subtitle of listing */
  232. /* scl */
  233. /* sect */
  234.   {"set", s_set, 0},
  235.   {"short", cons, 2},
  236.   {"single", float_cons, 'f'},
  237. /* size */
  238.   {"space", s_space, 0},
  239. /* tag */
  240.   {"text", s_text, 0},
  241.   {"title", listing_title, 0},    /* Listing title */
  242. /* type */
  243. /* use */
  244. /* val */
  245.   {"word", cons, 2},
  246.   {NULL}            /* end sentinel */
  247. };
  248.  
  249. static void 
  250. pobegin ()
  251. {
  252.   char *errtxt;            /* error text */
  253.   const pseudo_typeS *pop;
  254.  
  255.   po_hash = hash_new ();
  256.  
  257.   /* Do the target-specific pseudo ops. */
  258.   for (pop = md_pseudo_table; pop->poc_name; pop++)
  259.     {
  260.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  261.       if (errtxt && *errtxt)
  262.     {
  263.       as_fatal ("error constructing md pseudo-op table");
  264.     }            /* on error */
  265.     }                /* for each op */
  266.  
  267.   /* Now object specific.  Skip any that were in the target table. */
  268.   for (pop = obj_pseudo_table; pop->poc_name; pop++)
  269.     {
  270.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  271.       if (errtxt && *errtxt)
  272.     {
  273.       if (!strcmp (errtxt, "exists"))
  274.         {
  275. #ifdef DIE_ON_OVERRIDES
  276.           as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
  277. #endif /* DIE_ON_OVERRIDES */
  278.           continue;        /* OK if target table overrides. */
  279.         }
  280.       else
  281.         {
  282.           as_fatal ("error constructing obj pseudo-op table");
  283.         }            /* if overridden */
  284.     }            /* on error */
  285.     }                /* for each op */
  286.  
  287.   /* Now portable ones.  Skip any that we've seen already. */
  288.   for (pop = potable; pop->poc_name; pop++)
  289.     {
  290.       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
  291.       if (errtxt && *errtxt)
  292.     {
  293.       if (!strcmp (errtxt, "exists"))
  294.         {
  295. #ifdef DIE_ON_OVERRIDES
  296.           as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
  297. #endif /* DIE_ON_OVERRIDES */
  298.           continue;        /* OK if target table overrides. */
  299.         }
  300.       else
  301.         {
  302.           as_fatal ("error constructing obj pseudo-op table");
  303.         }            /* if overridden */
  304.     }            /* on error */
  305.     }                /* for each op */
  306.  
  307.   return;
  308. }                /* pobegin() */
  309.  
  310. #define HANDLE_CONDITIONAL_ASSEMBLY()    \
  311.   if (ignore_input ())                    \
  312.     {                            \
  313.       while (! is_end_of_line[*input_line_pointer++])    \
  314.     if (input_line_pointer == buffer_limit)        \
  315.       break;                    \
  316.       continue;                        \
  317.     }
  318.  
  319.  
  320. /*    read_a_source_file()
  321.  *
  322.  * We read the file, putting things into a web that
  323.  * represents what we have been reading.
  324.  */
  325. void 
  326. read_a_source_file (name)
  327.      char *name;
  328. {
  329.   register char c;
  330.   register char *s;        /* string of symbol, '\0' appended */
  331.   register int temp;
  332.   /* register struct frag * fragP; JF unused *//* a frag we just made */
  333.   pseudo_typeS *pop;
  334.  
  335.   buffer = input_scrub_new_file (name);
  336.  
  337.   listing_file (name);
  338.   listing_newline ("");
  339.  
  340.   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
  341.     {                /* We have another line to parse. */
  342.       know (buffer_limit[-1] == '\n');    /* Must have a sentinel. */
  343.     contin:            /* JF this goto is my fault I admit it.
  344.                    Someone brave please re-write the whole
  345.                    input section here?  Pleeze???  */
  346.       while (input_line_pointer < buffer_limit)
  347.     {
  348.       /* We have more of this buffer to parse. */
  349.  
  350.       /*
  351.        * We now have input_line_pointer->1st char of next line.
  352.        * If input_line_pointer [-1] == '\n' then we just
  353.        * scanned another line: so bump line counters.
  354.        */
  355.       if (input_line_pointer[-1] == '\n')
  356.         {
  357.           bump_line_counters ();
  358.  
  359. #ifdef MRI
  360.           /* Text at the start of a line must be a label, we run down and stick a colon in */
  361.           if (is_name_beginner (*input_line_pointer))
  362.         {
  363.           char *line_start = input_line_pointer;
  364.           char c = get_symbol_end ();
  365.           colon (line_start);
  366.           *input_line_pointer = c;
  367.           if (c == ':')
  368.             input_line_pointer++;
  369.  
  370.         }
  371. #endif
  372.         }
  373.  
  374.  
  375.       /*
  376.        * We are at the begining of a line, or similar place.
  377.        * We expect a well-formed assembler statement.
  378.        * A "symbol-name:" is a statement.
  379.        *
  380.        * Depending on what compiler is used, the order of these tests
  381.        * may vary to catch most common case 1st.
  382.        * Each test is independent of all other tests at the (top) level.
  383.        * PLEASE make a compiler that doesn't use this assembler.
  384.        * It is crufty to waste a compiler's time encoding things for this
  385.        * assembler, which then wastes more time decoding it.
  386.        * (And communicating via (linear) files is silly!
  387.        * If you must pass stuff, please pass a tree!)
  388.        */
  389.       if ((c = *input_line_pointer++) == '\t'
  390.           || c == ' '
  391.           || c == '\f'
  392.           || c == 0)
  393.         {
  394.           c = *input_line_pointer++;
  395.         }
  396.       know (c != ' ');    /* No further leading whitespace. */
  397.       LISTING_NEWLINE ();
  398.       /*
  399.        * C is the 1st significant character.
  400.        * Input_line_pointer points after that character.
  401.        */
  402.       if (is_name_beginner (c))
  403.         {            /* want user-defined label or pseudo/opcode */
  404.           HANDLE_CONDITIONAL_ASSEMBLY ();
  405.  
  406.           s = --input_line_pointer;
  407.           c = get_symbol_end ();    /* name's delimiter */
  408.           /*
  409.            * C is character after symbol.
  410.            * That character's place in the input line is now '\0'.
  411.            * S points to the beginning of the symbol.
  412.            *   [In case of pseudo-op, s->'.'.]
  413.            * Input_line_pointer->'\0' where c was.
  414.            */
  415.           if (TC_START_LABEL(c, input_line_pointer))
  416.         {
  417.           colon (s);    /* user-defined label */
  418.           *input_line_pointer++ = ':';    /* Put ':' back for error messages' sake. */
  419.           /* Input_line_pointer->after ':'. */
  420.           SKIP_WHITESPACE ();
  421.  
  422.  
  423.         }
  424.           else if (c == '=' || input_line_pointer[1] == '=')
  425.         {
  426.           equals (s);
  427.           demand_empty_rest_of_line ();
  428.         }
  429.           else
  430.         {        /* expect pseudo-op or machine instruction */
  431. #ifdef MRI
  432.           if (!done_pseudo (s))
  433.  
  434. #else
  435.           if (*s == '.')
  436.             {
  437.               /*
  438.                * PSEUDO - OP.
  439.                *
  440.                * WARNING: c has next char, which may be end-of-line.
  441.                * We lookup the pseudo-op table with s+1 because we
  442.                * already know that the pseudo-op begins with a '.'.
  443.                */
  444.  
  445.               pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
  446.  
  447.               /* Print the error msg now, while we still can */
  448.               if (!pop)
  449.             {
  450.               as_bad ("Unknown pseudo-op:  `%s'", s);
  451.               *input_line_pointer = c;
  452.               s_ignore (0);
  453.               break;
  454.             }
  455.  
  456.               /* Put it back for error messages etc. */
  457.               *input_line_pointer = c;
  458.               /* The following skip of whitespace is compulsory.
  459.              A well shaped space is sometimes all that separates
  460.              keyword from operands. */
  461.               if (c == ' ' || c == '\t')
  462.             {
  463.               input_line_pointer++;
  464.             }    /* Skip seperator after keyword. */
  465.               /*
  466.                * Input_line is restored.
  467.                * Input_line_pointer->1st non-blank char
  468.                * after pseudo-operation.
  469.                */
  470.               if (!pop)
  471.             {
  472.               ignore_rest_of_line ();
  473.               break;
  474.             }
  475.               else
  476.             {
  477.               (*pop->poc_handler) (pop->poc_val);
  478.             }    /* if we have one */
  479.             }
  480.           else
  481. #endif
  482.             {        /* machine instruction */
  483.               /* WARNING: c has char, which may be end-of-line. */
  484.               /* Also: input_line_pointer->`\0` where c was. */
  485.               *input_line_pointer = c;
  486.               while (!is_end_of_line[*input_line_pointer])
  487.             {
  488.               input_line_pointer++;
  489.             }
  490.  
  491.               c = *input_line_pointer;
  492.               *input_line_pointer = '\0';
  493.  
  494.               md_assemble (s);    /* Assemble 1 instruction. */
  495.  
  496.               *input_line_pointer++ = c;
  497.  
  498.               /* We resume loop AFTER the end-of-line from this instruction */
  499.             }        /* if (*s=='.') */
  500.  
  501.         }        /* if c==':' */
  502.           continue;
  503.         }            /* if (is_name_beginner(c) */
  504.  
  505.  
  506.       if (is_end_of_line[c])
  507.         {
  508.           continue;
  509.         }            /* empty statement */
  510.  
  511.  
  512. #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
  513.       if (isdigit (c))
  514.         {            /* local label  ("4:") */
  515.           char *backup = input_line_pointer;
  516.  
  517.           HANDLE_CONDITIONAL_ASSEMBLY ();
  518.  
  519.           temp = c - '0';
  520.  
  521.           while (isdigit (*input_line_pointer))
  522.         {
  523.           temp = (temp * 10) + *input_line_pointer - '0';
  524.           ++input_line_pointer;
  525.         }        /* read the whole number */
  526.  
  527. #ifdef LOCAL_LABELS_DOLLAR
  528.           if (*input_line_pointer == '$'
  529.           && *(input_line_pointer + 1) == ':')
  530.         {
  531.           input_line_pointer += 2;
  532.  
  533.           if (dollar_label_defined (temp))
  534.             {
  535.               as_fatal ("label \"%d$\" redefined", temp);
  536.             }
  537.  
  538.           define_dollar_label (temp);
  539.           colon (dollar_label_name (temp, 0));
  540.           continue;
  541.         }
  542. #endif /* LOCAL_LABELS_DOLLAR */
  543.  
  544. #ifdef LOCAL_LABELS_FB
  545.           if (*input_line_pointer++ == ':')
  546.         {
  547.           fb_label_instance_inc (temp);
  548.           colon (fb_label_name (temp, 0));
  549.           continue;
  550.         }
  551. #endif /* LOCAL_LABELS_FB */
  552.  
  553.           input_line_pointer = backup;
  554.         }            /* local label  ("4:") */
  555. #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
  556.  
  557.       if (c && strchr (line_comment_chars, c))
  558.         {            /* Its a comment.  Better say APP or NO_APP */
  559.           char *ends;
  560.           char *new_buf;
  561.           char *new_tmp;
  562.           int new_length;
  563.           char *tmp_buf = 0;
  564.           extern char *scrub_string, *scrub_last_string;
  565.  
  566.           bump_line_counters ();
  567.           s = input_line_pointer;
  568.           if (strncmp (s, "APP\n", 4))
  569.         continue;    /* We ignore it */
  570.           s += 4;
  571.  
  572.           ends = strstr (s, "#NO_APP\n");
  573.  
  574.           if (!ends)
  575.         {
  576.           int tmp_len;
  577.           int num;
  578.  
  579.           /* The end of the #APP wasn't in this buffer.  We
  580.              keep reading in buffers until we find the #NO_APP
  581.              that goes with this #APP  There is one.  The specs
  582.              guarentee it. . . */
  583.           tmp_len = buffer_limit - s;
  584.           tmp_buf = xmalloc (tmp_len + 1);
  585.           bcopy (s, tmp_buf, tmp_len);
  586.           do
  587.             {
  588.               new_tmp = input_scrub_next_buffer (&buffer);
  589.               if (!new_tmp)
  590.             break;
  591.               else
  592.             buffer_limit = new_tmp;
  593.               input_line_pointer = buffer;
  594.               ends = strstr (buffer, "#NO_APP\n");
  595.               if (ends)
  596.             num = ends - buffer;
  597.               else
  598.             num = buffer_limit - buffer;
  599.  
  600.               tmp_buf = xrealloc (tmp_buf, tmp_len + num);
  601.               bcopy (buffer, tmp_buf + tmp_len, num);
  602.               tmp_len += num;
  603.             }
  604.           while (!ends);
  605.  
  606.           input_line_pointer = ends ? ends + 8 : NULL;
  607.  
  608.           s = tmp_buf;
  609.           ends = s + tmp_len;
  610.  
  611.         }
  612.           else
  613.         {
  614.           input_line_pointer = ends + 8;
  615.         }
  616.           new_buf = xmalloc (100);
  617.           new_length = 100;
  618.           new_tmp = new_buf;
  619.  
  620.           scrub_string = s;
  621.           scrub_last_string = ends;
  622.           for (;;)
  623.         {
  624.           int ch;
  625.  
  626.           ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
  627.           if (ch == EOF)
  628.             break;
  629.           *new_tmp++ = ch;
  630.           if (new_tmp == new_buf + new_length)
  631.             {
  632.               new_buf = xrealloc (new_buf, new_length + 100);
  633.               new_tmp = new_buf + new_length;
  634.               new_length += 100;
  635.             }
  636.         }
  637.  
  638.           if (tmp_buf)
  639.         free (tmp_buf);
  640.           old_buffer = buffer;
  641.           old_input = input_line_pointer;
  642.           old_limit = buffer_limit;
  643.           buffer = new_buf;
  644.           input_line_pointer = new_buf;
  645.           buffer_limit = new_tmp;
  646.           continue;
  647.         }
  648.  
  649.       HANDLE_CONDITIONAL_ASSEMBLY ();
  650.  
  651.       /* as_warn("Junk character %d.",c);  Now done by ignore_rest */
  652.       input_line_pointer--;    /* Report unknown char as ignored. */
  653.       ignore_rest_of_line ();
  654.     }            /* while (input_line_pointer<buffer_limit) */
  655.       if (old_buffer)
  656.     {
  657.       bump_line_counters ();
  658.       if (old_input != 0)
  659.         {
  660.           buffer = old_buffer;
  661.           input_line_pointer = old_input;
  662.           buffer_limit = old_limit;
  663.           old_buffer = 0;
  664.           goto contin;
  665.         }
  666.     }
  667.     }                /* while (more buffers to scan) */
  668.   input_scrub_close ();        /* Close the input file */
  669.  
  670. }                /* read_a_source_file() */
  671.  
  672. void 
  673. s_abort ()
  674. {
  675.   as_fatal (".abort detected.  Abandoning ship.");
  676. }                /* s_abort() */
  677.  
  678. /* For machines where ".align 4" means align to a 4 byte boundary. */
  679. void 
  680. s_align_bytes (arg)
  681.      int arg;
  682. {
  683.   register unsigned int temp;
  684.   register long temp_fill;
  685.   unsigned int i = 0;
  686.   unsigned long max_alignment = 1 << 15;
  687.  
  688.   if (is_end_of_line[*input_line_pointer])
  689.     temp = arg;            /* Default value from pseudo-op table */
  690.   else
  691.     temp = get_absolute_expression ();
  692.  
  693.   if (temp > max_alignment)
  694.     {
  695.       as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  696.     }
  697.  
  698.   /*
  699.      * For the sparc, `.align (1<<n)' actually means `.align n'
  700.      * so we have to convert it.
  701.      */
  702.   if (temp != 0)
  703.     {
  704.       for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
  705.     ;
  706.     }
  707.   if (temp != 1)
  708.     as_bad ("Alignment not a power of 2");
  709.  
  710.   temp = i;
  711.   if (*input_line_pointer == ',')
  712.     {
  713.       input_line_pointer++;
  714.       temp_fill = get_absolute_expression ();
  715.     }
  716.   else if (now_seg != data_section && now_seg != bss_section)
  717.     temp_fill = NOP_OPCODE;
  718.   else
  719.     temp_fill = 0;
  720.   /* Only make a frag if we HAVE to. . . */
  721.   if (temp && !need_pass_2)
  722.     frag_align (temp, (int) temp_fill);
  723.  
  724.   demand_empty_rest_of_line ();
  725. }                /* s_align_bytes() */
  726.  
  727. /* For machines where ".align 4" means align to 2**4 boundary. */
  728. void 
  729. s_align_ptwo ()
  730. {
  731.   register int temp;
  732.   register long temp_fill;
  733.   long max_alignment = 15;
  734.  
  735.   temp = get_absolute_expression ();
  736.   if (temp > max_alignment)
  737.     as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  738.   else if (temp < 0)
  739.     {
  740.       as_bad ("Alignment negative. 0 assumed.");
  741.       temp = 0;
  742.     }
  743.   if (*input_line_pointer == ',')
  744.     {
  745.       input_line_pointer++;
  746.       temp_fill = get_absolute_expression ();
  747.     }
  748.   /* @@ Fix this right for BFD!  */
  749.   else if (now_seg != data_section && now_seg != bss_section)
  750.     temp_fill = NOP_OPCODE;
  751.   else
  752.     temp_fill = 0;
  753.   /* Only make a frag if we HAVE to. . . */
  754.   if (temp && !need_pass_2)
  755.     frag_align (temp, (int) temp_fill);
  756.  
  757.   record_alignment (now_seg, temp);
  758.  
  759.   demand_empty_rest_of_line ();
  760. }                /* s_align_ptwo() */
  761.  
  762. void 
  763. s_comm ()
  764. {
  765.   register char *name;
  766.   register char c;
  767.   register char *p;
  768.   register int temp;
  769.   register symbolS *symbolP;
  770.  
  771.   name = input_line_pointer;
  772.   c = get_symbol_end ();
  773.   /* just after name is now '\0' */
  774.   p = input_line_pointer;
  775.   *p = c;
  776.   SKIP_WHITESPACE ();
  777.   if (*input_line_pointer != ',')
  778.     {
  779.       as_bad ("Expected comma after symbol-name: rest of line ignored.");
  780.       ignore_rest_of_line ();
  781.       return;
  782.     }
  783.   input_line_pointer++;        /* skip ',' */
  784.   if ((temp = get_absolute_expression ()) < 0)
  785.     {
  786.       as_warn (".COMMon length (%d.) <0! Ignored.", temp);
  787.       ignore_rest_of_line ();
  788.       return;
  789.     }
  790.   *p = 0;
  791.   symbolP = symbol_find_or_make (name);
  792.   *p = c;
  793.   if (S_IS_DEFINED (symbolP))
  794.     {
  795.       as_bad ("Ignoring attempt to re-define symbol");
  796.       ignore_rest_of_line ();
  797.       return;
  798.     }
  799.   if (S_GET_VALUE (symbolP))
  800.     {
  801.       if (S_GET_VALUE (symbolP) != temp)
  802.     as_bad ("Length of .comm \"%s\" is already %d. Not changed to %d.",
  803.         S_GET_NAME (symbolP),
  804.         S_GET_VALUE (symbolP),
  805.         temp);
  806.     }
  807.   else
  808.     {
  809.       S_SET_VALUE (symbolP, temp);
  810.       S_SET_EXTERNAL (symbolP);
  811.     }
  812. #ifdef OBJ_VMS
  813.     if ( (!temp) || !flagseen['1'])
  814.         S_GET_OTHER(symbolP)  = const_flag;
  815. #endif /* not OBJ_VMS */
  816.   know (symbolP->sy_frag == &zero_address_frag);
  817.   demand_empty_rest_of_line ();
  818. }                /* s_comm() */
  819.  
  820. void
  821. s_data ()
  822. {
  823.   register int temp;
  824.  
  825.   temp = get_absolute_expression ();
  826. #ifdef BFD_ASSEMBLER
  827.   subseg_set (data_section, (subsegT) temp);
  828. #else
  829.   subseg_new (data_section, (subsegT) temp);
  830. #endif
  831.  
  832. #ifdef OBJ_VMS
  833.   const_flag = 0;
  834. #endif
  835.   demand_empty_rest_of_line ();
  836. }
  837.  
  838. void 
  839. s_app_file ()
  840. {
  841.   register char *s;
  842.   int length;
  843.  
  844.   /* Some assemblers tolerate immediately following '"' */
  845.   if ((s = demand_copy_string (&length)) != 0)
  846.     {
  847.       new_logical_line (s, -1);
  848.       demand_empty_rest_of_line ();
  849.     }
  850. #ifdef OBJ_COFF
  851.   c_dot_file_symbol (s);
  852. #endif /* OBJ_COFF */
  853. }                /* s_app_file() */
  854.  
  855. void 
  856. s_fill ()
  857. {
  858.   long temp_repeat = 0;
  859.   long temp_size = 1;
  860.   register long temp_fill = 0;
  861.   char *p;
  862.  
  863.  
  864.   temp_repeat = get_absolute_expression ();
  865.   if (*input_line_pointer == ',')
  866.     {
  867.       input_line_pointer++;
  868.       temp_size = get_absolute_expression ();
  869.       if (*input_line_pointer == ',')
  870.     {
  871.       input_line_pointer++;
  872.       temp_fill = get_absolute_expression ();
  873.     }
  874.     }
  875.   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
  876. #define BSD_FILL_SIZE_CROCK_8 (8)
  877.   if (temp_size > BSD_FILL_SIZE_CROCK_8)
  878.     {
  879.       as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
  880.       temp_size = BSD_FILL_SIZE_CROCK_8;
  881.     }
  882.   if (temp_size < 0)
  883.     {
  884.       as_warn ("Size negative: .fill ignored.");
  885.       temp_size = 0;
  886.     }
  887.   else if (temp_repeat <= 0)
  888.     {
  889.       as_warn ("Repeat < 0, .fill ignored");
  890.       temp_size = 0;
  891.     }
  892.  
  893.   if (temp_size && !need_pass_2)
  894.     {
  895.       p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
  896.       memset (p, 0, (int) temp_size);
  897.       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
  898.        * flavoured AS.  The following bizzare behaviour is to be
  899.        * compatible with above.  I guess they tried to take up to 8
  900.        * bytes from a 4-byte expression and they forgot to sign
  901.        * extend. Un*x Sux. */
  902. #define BSD_FILL_SIZE_CROCK_4 (4)
  903.       md_number_to_chars (p, temp_fill,
  904.               (temp_size > BSD_FILL_SIZE_CROCK_4
  905.                ? BSD_FILL_SIZE_CROCK_4
  906.                : (int) temp_size));
  907.       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
  908.        * but emits no error message because it seems a legal thing to do.
  909.        * It is a degenerate case of .fill but could be emitted by a compiler.
  910.        */
  911.     }
  912.   demand_empty_rest_of_line ();
  913. }
  914.  
  915. void 
  916. s_globl ()
  917. {
  918.   register char *name;
  919.   register int c;
  920.   register symbolS *symbolP;
  921.  
  922.   do
  923.     {
  924.       name = input_line_pointer;
  925.       c = get_symbol_end ();
  926.       symbolP = symbol_find_or_make (name);
  927.       *input_line_pointer = c;
  928.       SKIP_WHITESPACE ();
  929.       S_SET_EXTERNAL (symbolP);
  930.       if (c == ',')
  931.     {
  932.       input_line_pointer++;
  933.       SKIP_WHITESPACE ();
  934.       if (*input_line_pointer == '\n')
  935.         c = '\n';
  936.     }
  937.     }
  938.   while (c == ',');
  939.   demand_empty_rest_of_line ();
  940. }                /* s_globl() */
  941.  
  942. void 
  943. s_lcomm (needs_align)
  944.      /* 1 if this was a ".bss" directive, which may require a 3rd argument
  945.     (alignment); 0 if it was an ".lcomm" (2 args only)  */
  946.      int needs_align;
  947. {
  948.   register char *name;
  949.   register char c;
  950.   register char *p;
  951.   register int temp;
  952.   register symbolS *symbolP;
  953.   segT current_seg = now_seg;
  954.   subsegT current_subseg = now_subseg;
  955.   const int max_alignment = 15;
  956.   int align = 0;
  957.   segT bss_seg = bss_section;
  958.  
  959.   name = input_line_pointer;
  960.   c = get_symbol_end ();
  961.   p = input_line_pointer;
  962.   *p = c;
  963.   SKIP_WHITESPACE ();
  964.   if (*input_line_pointer != ',')
  965.     {
  966.       as_bad ("Expected comma after name");
  967.       ignore_rest_of_line ();
  968.       return;
  969.     }
  970.  
  971.   ++input_line_pointer;
  972.  
  973.   if (*input_line_pointer == '\n')
  974.     {
  975.       as_bad ("Missing size expression");
  976.       return;
  977.     }
  978.  
  979.   if ((temp = get_absolute_expression ()) < 0)
  980.     {
  981.       as_warn ("BSS length (%d.) <0! Ignored.", temp);
  982.       ignore_rest_of_line ();
  983.       return;
  984.     }
  985.  
  986. #ifdef TC_MIPS
  987. #ifdef OBJ_ECOFF
  988.   /* For MIPS ECOFF, small objects are put in .sbss.  */
  989.   if (temp <= bfd_get_gp_size (stdoutput))
  990.     bss_seg = subseg_new (".sbss", 1);
  991. #endif
  992. #endif
  993.  
  994.   if (needs_align)
  995.     {
  996.       align = 0;
  997.       SKIP_WHITESPACE ();
  998.       if (*input_line_pointer != ',')
  999.     {
  1000.       as_bad ("Expected comma after size");
  1001.       ignore_rest_of_line ();
  1002.       return;
  1003.     }
  1004.       input_line_pointer++;
  1005.       SKIP_WHITESPACE ();
  1006.       if (*input_line_pointer == '\n')
  1007.     {
  1008.       as_bad ("Missing alignment");
  1009.       return;
  1010.     }
  1011.       align = get_absolute_expression ();
  1012.       if (align > max_alignment)
  1013.     {
  1014.       align = max_alignment;
  1015.       as_warn ("Alignment too large: %d. assumed.", align);
  1016.     }
  1017.       else if (align < 0)
  1018.     {
  1019.       align = 0;
  1020.       as_warn ("Alignment negative. 0 assumed.");
  1021.     }
  1022.       record_alignment (bss_seg, align);
  1023.     }                /* if needs align */
  1024.  
  1025.   *p = 0;
  1026.   symbolP = symbol_find_or_make (name);
  1027.   *p = c;
  1028.  
  1029.   if (
  1030. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1031.        S_GET_OTHER (symbolP) == 0 &&
  1032.        S_GET_DESC (symbolP) == 0 &&
  1033. #endif /* OBJ_AOUT or OBJ_BOUT */
  1034.        (S_GET_SEGMENT (symbolP) == bss_seg
  1035.     || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
  1036.     {
  1037.       char *p;
  1038.  
  1039. #ifdef BFD_ASSEMBLER
  1040.       subseg_set (bss_seg, 1);
  1041. #else
  1042.       subseg_new (bss_seg, 1);
  1043. #endif
  1044.  
  1045.       if (align)
  1046.     frag_align (align, 0);
  1047.                     /* detach from old frag    */
  1048.       if (S_GET_SEGMENT (symbolP) == bss_seg)
  1049.     symbolP->sy_frag->fr_symbol = NULL;
  1050.  
  1051.       symbolP->sy_frag = frag_now;
  1052.       p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
  1053.             temp, (char *)0);
  1054.       *p = 0;
  1055.  
  1056.       S_SET_SEGMENT (symbolP, bss_seg);
  1057.  
  1058. #ifdef OBJ_COFF
  1059.       /* The symbol may already have been created with a preceding
  1060.          ".globl" directive -- be careful not to step on storage class
  1061.          in that case.  Otherwise, set it to static. */
  1062.       if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
  1063.     {
  1064.       S_SET_STORAGE_CLASS (symbolP, C_STAT);
  1065.     }
  1066. #endif /* OBJ_COFF */
  1067.     }
  1068.   else
  1069.     {
  1070.       as_bad ("Ignoring attempt to re-define symbol %s.", name);
  1071.     }
  1072.  
  1073. #ifdef BFD_ASSEMBLER
  1074.   subseg_set (current_seg, current_subseg);
  1075. #else
  1076.   subseg_new (current_seg, current_subseg);
  1077. #endif
  1078.  
  1079.   demand_empty_rest_of_line ();
  1080. }                /* s_lcomm() */
  1081.  
  1082. void
  1083. s_long ()
  1084. {
  1085.   cons (4);
  1086. }
  1087.  
  1088. void
  1089. s_int ()
  1090. {
  1091.   cons (4);
  1092. }
  1093.  
  1094. void 
  1095. s_lsym ()
  1096. {
  1097.   register char *name;
  1098.   register char c;
  1099.   register char *p;
  1100.   register segT segment;
  1101.   expressionS exp;
  1102.   register symbolS *symbolP;
  1103.  
  1104.   /* we permit ANY defined expression: BSD4.2 demands constants */
  1105.   name = input_line_pointer;
  1106.   c = get_symbol_end ();
  1107.   p = input_line_pointer;
  1108.   *p = c;
  1109.   SKIP_WHITESPACE ();
  1110.   if (*input_line_pointer != ',')
  1111.     {
  1112.       *p = 0;
  1113.       as_bad ("Expected comma after name \"%s\"", name);
  1114.       *p = c;
  1115.       ignore_rest_of_line ();
  1116.       return;
  1117.     }
  1118.   input_line_pointer++;
  1119.   segment = expression (&exp);
  1120.   if (segment != absolute_section
  1121.       && segment != reg_section
  1122.       && ! SEG_NORMAL (segment))
  1123.     {
  1124.       as_bad ("Bad expression: %s", segment_name (segment));
  1125.       ignore_rest_of_line ();
  1126.       return;
  1127.     }
  1128.   *p = 0;
  1129.   symbolP = symbol_find_or_make (name);
  1130.  
  1131.   /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
  1132.      symbolP->sy_desc == 0) out of this test because coff doesn't have
  1133.      those fields, and I can't see when they'd ever be tripped.  I
  1134.      don't think I understand why they were here so I may have
  1135.      introduced a bug. As recently as 1.37 didn't have this test
  1136.      anyway.  xoxorich. */
  1137.  
  1138.   if (S_GET_SEGMENT (symbolP) == undefined_section
  1139.       && S_GET_VALUE (symbolP) == 0)
  1140.     {
  1141.       /* The name might be an undefined .global symbol; be sure to
  1142.      keep the "external" bit. */
  1143.       S_SET_SEGMENT (symbolP, segment);
  1144.       S_SET_VALUE (symbolP, (valueT) (exp.X_add_number));
  1145.     }
  1146.   else
  1147.     {
  1148.       as_bad ("Symbol %s already defined", name);
  1149.     }
  1150.   *p = c;
  1151.   demand_empty_rest_of_line ();
  1152. }                /* s_lsym() */
  1153.  
  1154. void 
  1155. s_org ()
  1156. {
  1157.   register segT segment;
  1158.   expressionS exp;
  1159.   register long temp_fill;
  1160.   register char *p;
  1161.   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
  1162.      thing as a sub-segment-relative origin.  Any absolute origin is
  1163.      given a warning, then assumed to be segment-relative.  Any
  1164.      segmented origin expression ("foo+42") had better be in the right
  1165.      segment or the .org is ignored.
  1166.  
  1167.      BSD 4.2 AS warns if you try to .org backwards. We cannot because
  1168.      we never know sub-segment sizes when we are reading code.  BSD
  1169.      will crash trying to emit negative numbers of filler bytes in
  1170.      certain .orgs. We don't crash, but see as-write for that code.
  1171.  
  1172.      Don't make frag if need_pass_2==1.  */
  1173.   segment = get_known_segmented_expression (&exp);
  1174.   if (*input_line_pointer == ',')
  1175.     {
  1176.       input_line_pointer++;
  1177.       temp_fill = get_absolute_expression ();
  1178.     }
  1179.   else
  1180.     temp_fill = 0;
  1181.   if (!need_pass_2)
  1182.     {
  1183.       if (segment != now_seg && segment != absolute_section)
  1184.     as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
  1185.         segment_name (segment), segment_name (now_seg));
  1186.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  1187.             exp.X_add_number, (char *) 0);
  1188.       *p = temp_fill;
  1189.     }                /* if (ok to make frag) */
  1190.   demand_empty_rest_of_line ();
  1191. }                /* s_org() */
  1192.  
  1193. void 
  1194. s_set ()
  1195. {
  1196.   register char *name;
  1197.   register char delim;
  1198.   register char *end_name;
  1199.   register symbolS *symbolP;
  1200.  
  1201.   /*
  1202.    * Especial apologies for the random logic:
  1203.    * this just grew, and could be parsed much more simply!
  1204.    * Dean in haste.
  1205.    */
  1206.   name = input_line_pointer;
  1207.   delim = get_symbol_end ();
  1208.   end_name = input_line_pointer;
  1209.   *end_name = delim;
  1210.   SKIP_WHITESPACE ();
  1211.  
  1212.   if (*input_line_pointer != ',')
  1213.     {
  1214.       *end_name = 0;
  1215.       as_bad ("Expected comma after name \"%s\"", name);
  1216.       *end_name = delim;
  1217.       ignore_rest_of_line ();
  1218.       return;
  1219.     }
  1220.  
  1221.   input_line_pointer++;
  1222.   *end_name = 0;
  1223.  
  1224.   if (name[0] == '.' && name[1] == '\0')
  1225.     {
  1226.       /* Turn '. = mumble' into a .org mumble */
  1227.       register segT segment;
  1228.       expressionS exp;
  1229.       register char *ptr;
  1230.  
  1231.       segment = get_known_segmented_expression (&exp);
  1232.  
  1233.       if (!need_pass_2)
  1234.     {
  1235.       if (segment != now_seg && segment != absolute_section)
  1236.         as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
  1237.             segment_name (segment),
  1238.             segment_name (now_seg));
  1239.       ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  1240.               exp.X_add_number, (char *) 0);
  1241.       *ptr = 0;
  1242.     }            /* if (ok to make frag) */
  1243.  
  1244.       *end_name = delim;
  1245.       return;
  1246.     }
  1247.  
  1248.   if ((symbolP = symbol_find (name)) == NULL
  1249.       && (symbolP = md_undefined_symbol (name)) == NULL)
  1250.     {
  1251.       symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
  1252. #ifdef OBJ_COFF
  1253.       /* "set" symbols are local unless otherwise specified. */
  1254.       SF_SET_LOCAL (symbolP);
  1255. #endif /* OBJ_COFF */
  1256.  
  1257.     }                /* make a new symbol */
  1258.  
  1259.   symbol_table_insert (symbolP);
  1260.  
  1261.   *end_name = delim;
  1262.   pseudo_set (symbolP);
  1263.   demand_empty_rest_of_line ();
  1264. }                /* s_set() */
  1265.  
  1266. void 
  1267. s_space (mult)
  1268.      int mult;
  1269. {
  1270.   long temp_repeat;
  1271.   register long temp_fill;
  1272.   register char *p;
  1273.  
  1274.   /* Just like .fill, but temp_size = 1 */
  1275.   if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
  1276.     {
  1277.       temp_fill = get_absolute_expression ();
  1278.     }
  1279.   else
  1280.     {
  1281.       input_line_pointer--;    /* Backup over what was not a ','. */
  1282.       temp_fill = 0;
  1283.     }
  1284.   if (mult)
  1285.     {
  1286.       temp_repeat *= mult;
  1287.     }
  1288.   if (temp_repeat <= 0)
  1289.     {
  1290.       as_warn ("Repeat < 0, .space ignored");
  1291.       ignore_rest_of_line ();
  1292.       return;
  1293.     }
  1294.   if (!need_pass_2)
  1295.     {
  1296.       p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
  1297.             temp_repeat, (char *) 0);
  1298.       *p = temp_fill;
  1299.     }
  1300.   demand_empty_rest_of_line ();
  1301. }                /* s_space() */
  1302.  
  1303. void
  1304. s_text ()
  1305. {
  1306.   register int temp;
  1307.  
  1308.   temp = get_absolute_expression ();
  1309. #ifdef BFD_ASSEMBLER
  1310.   subseg_set (text_section, (subsegT) temp);
  1311. #else
  1312.   subseg_new (text_section, (subsegT) temp);
  1313. #endif
  1314.   demand_empty_rest_of_line ();
  1315. }                /* s_text() */
  1316.  
  1317.  
  1318. void 
  1319. demand_empty_rest_of_line ()
  1320. {
  1321.   SKIP_WHITESPACE ();
  1322.   if (is_end_of_line[*input_line_pointer])
  1323.     {
  1324.       input_line_pointer++;
  1325.     }
  1326.   else
  1327.     {
  1328.       ignore_rest_of_line ();
  1329.     }
  1330.   /* Return having already swallowed end-of-line. */
  1331. }                /* Return pointing just after end-of-line. */
  1332.  
  1333. void
  1334. ignore_rest_of_line ()        /* For suspect lines: gives warning. */
  1335. {
  1336.   if (!is_end_of_line[*input_line_pointer])
  1337.     {
  1338.       if (isprint (*input_line_pointer))
  1339.     as_bad ("Rest of line ignored. First ignored character is `%c'.",
  1340.         *input_line_pointer);
  1341.       else
  1342.     as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
  1343.         *input_line_pointer);
  1344.       while (input_line_pointer < buffer_limit
  1345.          && !is_end_of_line[*input_line_pointer])
  1346.     {
  1347.       input_line_pointer++;
  1348.     }
  1349.     }
  1350.   input_line_pointer++;        /* Return pointing just after end-of-line. */
  1351.   know (is_end_of_line[input_line_pointer[-1]]);
  1352. }
  1353.  
  1354. /*
  1355.  *            pseudo_set()
  1356.  *
  1357.  * In:    Pointer to a symbol.
  1358.  *    Input_line_pointer->expression.
  1359.  *
  1360.  * Out:    Input_line_pointer->just after any whitespace after expression.
  1361.  *    Tried to set symbol to value of expression.
  1362.  *    Will change symbols type, value, and frag;
  1363.  *    May set need_pass_2 == 1.
  1364.  */
  1365. void
  1366. pseudo_set (symbolP)
  1367.      symbolS *symbolP;
  1368. {
  1369.   expressionS exp;
  1370.   register segT segment;
  1371. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1372.   int ext;
  1373. #endif /* OBJ_AOUT or OBJ_BOUT */
  1374.  
  1375.   know (symbolP);        /* NULL pointer is logic error. */
  1376. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1377.   /* @@ Fix this right for BFD.  */
  1378.   ext = S_IS_EXTERNAL (symbolP);
  1379. #endif /* OBJ_AOUT or OBJ_BOUT */
  1380.  
  1381.   if ((segment = expression (&exp)) == absent_section)
  1382.     {
  1383.       as_bad ("Missing expression: absolute 0 assumed");
  1384.       exp.X_seg = absolute_section;
  1385.       exp.X_add_number = 0;
  1386.     }
  1387.  
  1388.   if (segment == reg_section)
  1389.     {
  1390.       S_SET_SEGMENT (symbolP, reg_section);
  1391.       S_SET_VALUE (symbolP, exp.X_add_number);
  1392.       symbolP->sy_frag = &zero_address_frag;
  1393.     }
  1394.   else if (segment == big_section)
  1395.     {
  1396.       as_bad ("%s number invalid. Absolute 0 assumed.",
  1397.           exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
  1398.       S_SET_SEGMENT (symbolP, absolute_section);
  1399. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1400.       /* @@ Fix this right for BFD.  */
  1401.       ext ? S_SET_EXTERNAL (symbolP) :
  1402.     S_CLEAR_EXTERNAL (symbolP);
  1403. #endif /* OBJ_AOUT or OBJ_BOUT */
  1404.       S_SET_VALUE (symbolP, 0);
  1405.       symbolP->sy_frag = &zero_address_frag;
  1406.     }
  1407.   else if (segment == absent_section)
  1408.     {
  1409.       as_warn ("No expression:  Using absolute 0");
  1410.       S_SET_SEGMENT (symbolP, absolute_section);
  1411. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1412.       /* @@ Fix this right for BFD.  */
  1413.       ext ? S_SET_EXTERNAL (symbolP) :
  1414.     S_CLEAR_EXTERNAL (symbolP);
  1415. #endif /* OBJ_AOUT or OBJ_BOUT */
  1416.       S_SET_VALUE (symbolP, 0);
  1417.       symbolP->sy_frag = &zero_address_frag;
  1418.     }
  1419.   else if (segment == diff_section)
  1420.     {
  1421.       if (exp.X_add_symbol && exp.X_subtract_symbol
  1422.       && (S_GET_SEGMENT (exp.X_add_symbol) ==
  1423.           S_GET_SEGMENT (exp.X_subtract_symbol)))
  1424.     {
  1425.       if (exp.X_add_symbol->sy_frag == exp.X_subtract_symbol->sy_frag)
  1426.         {
  1427.           exp.X_add_number += S_GET_VALUE (exp.X_add_symbol) -
  1428.         S_GET_VALUE (exp.X_subtract_symbol);
  1429.           goto abs;
  1430.         }
  1431.       as_bad ("Invalid expression: separation between symbols `%s'",
  1432.           S_GET_NAME (exp.X_add_symbol));
  1433.       as_bad (" and `%s' may not be constant",
  1434.           S_GET_NAME (exp.X_subtract_symbol));
  1435.       need_pass_2++;
  1436.     }
  1437.       else
  1438.     {
  1439.       as_bad ("Complex expression. Absolute segment assumed.");
  1440.       goto abs;
  1441.     }
  1442.     }
  1443.   else if (segment == absolute_section)
  1444.     {
  1445.     abs:
  1446.       S_SET_SEGMENT (symbolP, absolute_section);
  1447. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1448.       /* @@ Fix this right for BFD.  */
  1449.       ext ? S_SET_EXTERNAL (symbolP) :
  1450.     S_CLEAR_EXTERNAL (symbolP);
  1451. #endif /* OBJ_AOUT or OBJ_BOUT */
  1452.       S_SET_VALUE (symbolP, exp.X_add_number);
  1453.       symbolP->sy_frag = &zero_address_frag;
  1454.     }
  1455.   else if (segment == pass1_section)
  1456.     {
  1457.       symbolP->sy_forward = exp.X_add_symbol;
  1458.       as_bad ("Unknown expression");
  1459.       know (need_pass_2 == 1);
  1460.     }
  1461.   else if (segment == undefined_section)
  1462.     {
  1463.       symbolP->sy_forward = exp.X_add_symbol;
  1464.     }
  1465.   else
  1466.     {
  1467. #ifndef BFD_ASSEMBLER
  1468. #ifndef MANY_SEGMENTS
  1469.       switch (segment)
  1470.     {
  1471.     case SEG_DATA:
  1472.     case SEG_TEXT:
  1473.     case SEG_BSS:
  1474.       break;
  1475.  
  1476.     default:
  1477.       as_fatal ("failed sanity check.");
  1478.     }            /* switch on segment */
  1479. #endif
  1480. #endif
  1481.       S_SET_SEGMENT (symbolP, segment);
  1482. #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
  1483.       /* @@ Fix this right for BFD!  */
  1484.       if (ext)
  1485.     {
  1486.       S_SET_EXTERNAL (symbolP);
  1487.     }
  1488.       else
  1489.     {
  1490.       S_CLEAR_EXTERNAL (symbolP);
  1491.     }            /* if external */
  1492. #endif /* OBJ_AOUT or OBJ_BOUT */
  1493.  
  1494.       S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
  1495.       symbolP->sy_frag = exp.X_add_symbol->sy_frag;
  1496.     }
  1497. }
  1498.  
  1499. /*
  1500.  *            cons()
  1501.  *
  1502.  * CONStruct more frag of .bytes, or .words etc.
  1503.  * Should need_pass_2 be 1 then emit no frag(s).
  1504.  * This understands EXPRESSIONS, as opposed to big_cons().
  1505.  *
  1506.  * Bug (?)
  1507.  *
  1508.  * This has a split personality. We use expression() to read the
  1509.  * value. We can detect if the value won't fit in a byte or word.
  1510.  * But we can't detect if expression() discarded significant digits
  1511.  * in the case of a long. Not worth the crocks required to fix it.
  1512.  */
  1513.  
  1514. /* worker to do .byte etc statements */
  1515. /* clobbers input_line_pointer, checks */
  1516. /* end-of-line. */
  1517. void 
  1518. cons (nbytes)
  1519.      register unsigned int nbytes;    /* 1=.byte, 2=.word, 4=.long */
  1520. {
  1521.   register char c;
  1522.   register long mask;        /* High-order bits we will left-truncate, */
  1523.   /* but includes sign bit also. */
  1524.   register long get;        /* what we get */
  1525.   register long use;        /* get after truncation. */
  1526.   register long unmask;        /* what bits we will store */
  1527.   register char *p;
  1528.   register segT segment;
  1529.   expressionS exp;
  1530.  
  1531.   /*
  1532.    * Input_line_pointer->1st char after pseudo-op-code and could legally
  1533.    * be a end-of-line. (Or, less legally an eof - which we cope with.)
  1534.    */
  1535.   /* JF << of >= number of bits in the object is undefined.  In particular
  1536.      SPARC (Sun 4) has problems */
  1537.  
  1538.   if (nbytes >= sizeof (long))
  1539.     {
  1540.       mask = 0;
  1541.     }
  1542.   else
  1543.     {
  1544.       mask = ~0 << (BITS_PER_CHAR * nbytes);    /* Don't store these bits. */
  1545.     }                /* bigger than a long */
  1546.  
  1547.   unmask = ~mask;        /* Do store these bits. */
  1548.  
  1549. #ifdef NEVER
  1550.   "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
  1551.   mask = ~(unmask >> 1);    /* Includes sign bit now. */
  1552. #endif
  1553.  
  1554.   /*
  1555.    * The following awkward logic is to parse ZERO or more expressions,
  1556.    * comma seperated. Recall an expression includes its leading &
  1557.    * trailing blanks. We fake a leading ',' if there is (supposed to
  1558.    * be) a 1st expression, and keep demanding 1 expression for each ','.
  1559.    */
  1560.   if (is_it_end_of_statement ())
  1561.     {
  1562.       c = 0;            /* Skip loop. */
  1563.       input_line_pointer++;    /* Matches end-of-loop 'correction'. */
  1564.     }
  1565.   else
  1566.     {
  1567.       c = ',';
  1568.     }                /* if the end else fake it */
  1569.  
  1570.   /* Do loop. */
  1571.   while (c == ',')
  1572.     {
  1573. #ifdef WANT_BITFIELDS
  1574.       unsigned int bits_available = BITS_PER_CHAR * nbytes;
  1575.       /* used for error messages and rescanning */
  1576.       char *hold = input_line_pointer;
  1577. #endif /* WANT_BITFIELDS */
  1578. #ifdef MRI
  1579.       if (*input_line_pointer == '\'')
  1580.     {
  1581.       /* An MRI style string, cut into as many bytes as will fit
  1582.        into a nbyte chunk, left justify if necessary, and sepatate
  1583.        with commas so we can try again later */
  1584.       int scan = 0;
  1585.       unsigned int result = 0;
  1586.       input_line_pointer++;
  1587.       for (scan = 0; scan < nbytes; scan++)
  1588.         {
  1589.           if (*input_line_pointer == '\'')
  1590.         {
  1591.           if (input_line_pointer[1] == '\'')
  1592.             {
  1593.               input_line_pointer++;
  1594.             }
  1595.           else
  1596.             break;
  1597.         }
  1598.           result = (result << 8) | (*input_line_pointer++);
  1599.         }
  1600.  
  1601.       /* Left justify */
  1602.       while (scan < nbytes)
  1603.         {
  1604.           result <<= 8;
  1605.           scan++;
  1606.         }
  1607.       /* Create correct expression */
  1608.       exp.X_add_symbol = 0;
  1609.       exp.X_add_number = result;
  1610.       exp.X_seg = segment = absolute_section;
  1611.       /* Fake it so that we can read the next char too */
  1612.       if (input_line_pointer[0] != '\'' ||
  1613.        (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
  1614.         {
  1615.           input_line_pointer -= 2;
  1616.           input_line_pointer[0] = ',';
  1617.           input_line_pointer[1] = '\'';
  1618.         }
  1619.       else
  1620.         input_line_pointer++;
  1621.  
  1622.     }
  1623.       else
  1624. #endif
  1625.     /* At least scan over the expression. */
  1626.     segment = expression (&exp);
  1627.  
  1628. #ifdef WANT_BITFIELDS
  1629.       /* Some other assemblers, (eg, asm960), allow
  1630.      bitfields after ".byte" as w:x,y:z, where w and
  1631.      y are bitwidths and x and y are values.  They
  1632.      then pack them all together. We do a little
  1633.      better in that we allow them in words, longs,
  1634.      etc. and we'll pack them in target byte order
  1635.      for you.
  1636.     
  1637.      The rules are: pack least significat bit first,
  1638.      if a field doesn't entirely fit, put it in the
  1639.      next unit.  Overflowing the bitfield is
  1640.      explicitly *not* even a warning.  The bitwidth
  1641.      should be considered a "mask".
  1642.     
  1643.      FIXME-SOMEDAY: If this is considered generally
  1644.      useful, this logic should probably be reworked.
  1645.      xoxorich. */
  1646.  
  1647.       if (*input_line_pointer == ':')
  1648.     {            /* bitfields */
  1649.       long value = 0;
  1650.  
  1651.       for (;;)
  1652.         {
  1653.           unsigned long width;
  1654.  
  1655.           if (*input_line_pointer != ':')
  1656.         {
  1657.           input_line_pointer = hold;
  1658.           break;
  1659.         }        /* next piece is not a bitfield */
  1660.  
  1661.           /* In the general case, we can't allow
  1662.          full expressions with symbol
  1663.          differences and such.  The relocation
  1664.          entries for symbols not defined in this
  1665.          assembly would require arbitrary field
  1666.          widths, positions, and masks which most
  1667.          of our current object formats don't
  1668.          support.
  1669.         
  1670.          In the specific case where a symbol
  1671.          *is* defined in this assembly, we
  1672.          *could* build fixups and track it, but
  1673.          this could lead to confusion for the
  1674.          backends.  I'm lazy. I'll take any
  1675.          SEG_ABSOLUTE. I think that means that
  1676.          you can use a previous .set or
  1677.          .equ type symbol.  xoxorich. */
  1678.  
  1679.           if (segment == absent_section)
  1680.         {
  1681.           as_warn ("Using a bit field width of zero.");
  1682.           exp.X_add_number = 0;
  1683.           segment = absolute_section;
  1684.         }        /* implied zero width bitfield */
  1685.  
  1686.           if (segment != absolute_section)
  1687.         {
  1688.           *input_line_pointer = '\0';
  1689.           as_bad ("Field width \"%s\" too complex for a bitfield.\n", hold);
  1690.           *input_line_pointer = ':';
  1691.           demand_empty_rest_of_line ();
  1692.           return;
  1693.         }        /* too complex */
  1694.  
  1695.           if ((width = exp.X_add_number) > (BITS_PER_CHAR * nbytes))
  1696.         {
  1697.           as_warn ("Field width %d too big to fit in %d bytes: truncated to %d bits.",
  1698.                width, nbytes, (BITS_PER_CHAR * nbytes));
  1699.           width = BITS_PER_CHAR * nbytes;
  1700.         }        /* too big */
  1701.  
  1702.           if (width > bits_available)
  1703.         {
  1704.           /* FIXME-SOMEDAY: backing up and
  1705.              reparsing is wasteful */
  1706.           input_line_pointer = hold;
  1707.           exp.X_add_number = value;
  1708.           break;
  1709.         }        /* won't fit */
  1710.  
  1711.           hold = ++input_line_pointer;    /* skip ':' */
  1712.  
  1713.           if ((segment = expression (&exp)) != absolute_section)
  1714.         {
  1715.           char cache = *input_line_pointer;
  1716.  
  1717.           *input_line_pointer = '\0';
  1718.           as_bad ("Field value \"%s\" too complex for a bitfield.\n", hold);
  1719.           *input_line_pointer = cache;
  1720.           demand_empty_rest_of_line ();
  1721.           return;
  1722.         }        /* too complex */
  1723.  
  1724.           value |= (~(-1 << width) & exp.X_add_number)
  1725.         << ((BITS_PER_CHAR * nbytes) - bits_available);
  1726.  
  1727.           if ((bits_available -= width) == 0
  1728.           || is_it_end_of_statement ()
  1729.           || *input_line_pointer != ',')
  1730.         {
  1731.           break;
  1732.         }        /* all the bitfields we're gonna get */
  1733.  
  1734.           hold = ++input_line_pointer;
  1735.           segment = expression (&exp);
  1736.         }            /* forever loop */
  1737.  
  1738.       exp.X_add_number = value;
  1739.       segment = absolute_section;
  1740.     }            /* if looks like a bitfield */
  1741. #endif /* WANT_BITFIELDS */
  1742.  
  1743.       if (!need_pass_2)
  1744.     {            /* Still worthwhile making frags. */
  1745.  
  1746.       /* Don't call this if we are going to junk this pass anyway! */
  1747.       know (segment != pass1_section);
  1748.  
  1749.       if (segment == diff_section && exp.X_add_symbol == NULL)
  1750.         {
  1751.           as_bad ("Subtracting symbol \"%s\"(segment\"%s\") is too hard. Absolute segment assumed.",
  1752.               S_GET_NAME (exp.X_subtract_symbol),
  1753.               segment_name (S_GET_SEGMENT (exp.X_subtract_symbol)));
  1754.           segment = absolute_section;
  1755.           /* Leave exp . X_add_number alone. */
  1756.         }
  1757.       p = frag_more (nbytes);
  1758.       if (segment == big_section)
  1759.         {
  1760.           as_bad ("%s number invalid. Absolute 0 assumed.",
  1761.               exp.X_add_number > 0 ? "Bignum" : "Floating-Point");
  1762.           md_number_to_chars (p, (long) 0, nbytes);
  1763.         }
  1764.       else if (segment == absent_section)
  1765.         {
  1766.           as_warn ("0 assumed for missing expression");
  1767.           exp.X_add_number = 0;
  1768.           know (exp.X_add_symbol == NULL);
  1769.           goto abs_sec;
  1770.         }
  1771.       else if (segment == absolute_section)
  1772.         {
  1773.         abs_sec:
  1774.           get = exp.X_add_number;
  1775.           use = get & unmask;
  1776.           if ((get & mask) && (get & mask) != mask)
  1777.         {        /* Leading bits contain both 0s & 1s. */
  1778.           as_warn ("Value 0x%x truncated to 0x%x.", get, use);
  1779.         }
  1780.           md_number_to_chars (p, use, nbytes);    /* put bytes in right order. */
  1781.         }
  1782.       else if (segment == diff_section)
  1783.         {
  1784. #ifndef WORKING_DOT_WORD
  1785.           if (nbytes == 2)
  1786.         {
  1787.           struct broken_word *x;
  1788.  
  1789.           x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
  1790.           x->next_broken_word = broken_words;
  1791.           broken_words = x;
  1792.           x->frag = frag_now;
  1793.           x->word_goes_here = p;
  1794.           x->dispfrag = 0;
  1795.           x->add = exp.X_add_symbol;
  1796.           x->sub = exp.X_subtract_symbol;
  1797.           x->addnum = exp.X_add_number;
  1798.           x->added = 0;
  1799.           new_broken_words++;
  1800.           goto after_switch;
  1801.         }
  1802. #endif
  1803.           goto defalt;
  1804.         }
  1805.       else
  1806.         /* undefined_section, others */
  1807.         {
  1808.         defalt:
  1809.           md_number_to_chars (p, (long) 0, nbytes);
  1810. #ifdef BFD_ASSEMBLER
  1811.           fix_new (frag_now, p - frag_now->fr_literal, nbytes,
  1812.                exp.X_add_symbol, exp.X_subtract_symbol,
  1813.                exp.X_add_number, 0,
  1814.                /* @@ Should look at CPU word size.  */
  1815.                BFD_RELOC_32);
  1816. #else
  1817. #ifdef TC_NS32K
  1818.           fix_new_ns32k (frag_now, p - frag_now->fr_literal, nbytes,
  1819.                  exp.X_add_symbol, exp.X_subtract_symbol,
  1820.                  exp.X_add_number, 0, 0, 2, 0, 0);
  1821. #else
  1822. #if defined(TC_SPARC) || defined(TC_A29K)
  1823.           fix_new (frag_now, p - frag_now->fr_literal, nbytes,
  1824.                exp.X_add_symbol, exp.X_subtract_symbol,
  1825.                exp.X_add_number, 0, RELOC_32);
  1826. #else
  1827. #if defined(TC_H8300)
  1828.           fix_new (frag_now, p - frag_now->fr_literal, nbytes,
  1829.                exp.X_add_symbol, exp.X_subtract_symbol,
  1830.                exp.X_add_number, 0, R_RELWORD);
  1831.  
  1832. #else
  1833. #ifdef NO_RELOC
  1834.           fix_new (frag_now, p - frag_now->fr_literal, nbytes,
  1835.                exp.X_add_symbol, exp.X_subtract_symbol,
  1836.                exp.X_add_number, 0, NO_RELOC);
  1837. #else
  1838.           fix_new (frag_now, p - frag_now->fr_literal, nbytes,
  1839.                exp.X_add_symbol, exp.X_subtract_symbol,
  1840.                exp.X_add_number, 0, 0);
  1841. #endif /* NO_RELOC */
  1842. #endif /* tc_h8300 */
  1843. #endif /* tc_sparc|tc_a29k */
  1844. #endif /* TC_NS32K */
  1845. #endif /* BFD_ASSEMBLER */
  1846.         }            /* switch(segment) */
  1847.     after_switch:
  1848.       ;
  1849.     }            /* if (!need_pass_2) */
  1850.       c = *input_line_pointer++;
  1851.     }                /* while(c==',') */
  1852.   input_line_pointer--;        /* Put terminator back into stream. */
  1853.   demand_empty_rest_of_line ();
  1854. }                /* cons() */
  1855.  
  1856. /*
  1857.  *            big_cons()
  1858.  *
  1859.  * CONStruct more frag(s) of .quads, or .octa etc.
  1860.  * Makes 0 or more new frags.
  1861.  * If need_pass_2 == 1, generate no frag.
  1862.  * This understands only bignums, not expressions. Cons() understands
  1863.  * expressions.
  1864.  *
  1865.  * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
  1866.  *
  1867.  * This creates objects with struct obstack_control objs, destroying
  1868.  * any context objs held about a partially completed object. Beware!
  1869.  *
  1870.  *
  1871.  * I think it sucks to have 2 different types of integers, with 2
  1872.  * routines to read them, store them etc.
  1873.  * It would be nicer to permit bignums in expressions and only
  1874.  * complain if the result overflowed. However, due to "efficiency"...
  1875.  */
  1876. /* worker to do .quad etc statements */
  1877. /* clobbers input_line_pointer, checks */
  1878. /* end-of-line. */
  1879. /* 8=.quad 16=.octa ... */
  1880.  
  1881. void 
  1882. big_cons (nbytes)
  1883.      register int nbytes;
  1884. {
  1885.   register char c;        /* input_line_pointer->c. */
  1886.   register int radix;
  1887.   register long length;        /* Number of chars in an object. */
  1888.   register int digit;        /* Value of 1 digit. */
  1889.   register int carry;        /* For multi-precision arithmetic. */
  1890.   register int work;        /* For multi-precision arithmetic. */
  1891.   register char *p;        /* For multi-precision arithmetic. */
  1892.  
  1893.   extern const char hex_value[];    /* In hex_value.c. */
  1894.  
  1895.   /*
  1896.    * The following awkward logic is to parse ZERO or more strings,
  1897.    * comma seperated. Recall an expression includes its leading &
  1898.    * trailing blanks. We fake a leading ',' if there is (supposed to
  1899.    * be) a 1st expression, and keep demanding 1 expression for each ','.
  1900.    */
  1901.   if (is_it_end_of_statement ())
  1902.     {
  1903.       c = 0;            /* Skip loop. */
  1904.     }
  1905.   else
  1906.     {
  1907.       c = ',';            /* Do loop. */
  1908.       --input_line_pointer;
  1909.     }
  1910.   while (c == ',')
  1911.     {
  1912.       ++input_line_pointer;
  1913.       SKIP_WHITESPACE ();
  1914.       c = *input_line_pointer;
  1915.       /* C contains 1st non-blank character of what we hope is a number. */
  1916.       if (c == '0')
  1917.     {
  1918.       c = *++input_line_pointer;
  1919.       if (c == 'x' || c == 'X')
  1920.         {
  1921.           c = *++input_line_pointer;
  1922.           radix = 16;
  1923.         }
  1924.       else
  1925.         {
  1926.           radix = 8;
  1927.         }
  1928.     }
  1929.       else
  1930.     {
  1931.       radix = 10;
  1932.     }
  1933.       /*
  1934.        * This feature (?) is here to stop people worrying about
  1935.        * mysterious zero constants: which is what they get when
  1936.        * they completely omit digits.
  1937.        */
  1938.       if (hex_value[c] >= radix)
  1939.     {
  1940.       as_bad ("Missing digits. 0 assumed.");
  1941.     }
  1942.       bignum_high = bignum_low - 1;    /* Start constant with 0 chars. */
  1943.       for (; (digit = hex_value[c]) < radix; c = *++input_line_pointer)
  1944.     {
  1945.       /* Multiply existing number by radix, then add digit. */
  1946.       carry = digit;
  1947.       for (p = bignum_low; p <= bignum_high; p++)
  1948.         {
  1949.           work = (*p & MASK_CHAR) * radix + carry;
  1950.           *p = work & MASK_CHAR;
  1951.           carry = work >> BITS_PER_CHAR;
  1952.         }
  1953.       if (carry)
  1954.         {
  1955.           grow_bignum ();
  1956.           *bignum_high = carry & MASK_CHAR;
  1957.           know ((carry & ~MASK_CHAR) == 0);
  1958.         }
  1959.     }
  1960.       length = bignum_high - bignum_low + 1;
  1961.       if (length > nbytes)
  1962.     {
  1963.       as_warn ("Most significant bits truncated in integer constant.");
  1964.     }
  1965.       else
  1966.     {
  1967.       register long leading_zeroes;
  1968.  
  1969.       for (leading_zeroes = nbytes - length;
  1970.            leading_zeroes;
  1971.            leading_zeroes--)
  1972.         {
  1973.           grow_bignum ();
  1974.           *bignum_high = 0;
  1975.         }
  1976.     }
  1977.       if (!need_pass_2)
  1978.     {
  1979.       char *src = bignum_low;
  1980.       p = frag_more (nbytes);
  1981.       if (target_big_endian)
  1982.         {
  1983.           int i;
  1984.           for (i = nbytes - 1; i >= 0; i--)
  1985.         p[i] = *src++;
  1986.         }
  1987.       else
  1988.         bcopy (bignum_low, p, (int) nbytes);
  1989.     }
  1990.       /* C contains character after number. */
  1991.       SKIP_WHITESPACE ();
  1992.       c = *input_line_pointer;
  1993.       /* C contains 1st non-blank character after number. */
  1994.     }
  1995.   demand_empty_rest_of_line ();
  1996. }                /* big_cons() */
  1997.  
  1998. /* Extend bignum by 1 char. */
  1999. static void 
  2000. grow_bignum ()
  2001. {
  2002.   register long length;
  2003.  
  2004.   bignum_high++;
  2005.   if (bignum_high >= bignum_limit)
  2006.     {
  2007.       length = bignum_limit - bignum_low;
  2008.       bignum_low = xrealloc (bignum_low, length + length);
  2009.       bignum_high = bignum_low + length;
  2010.       bignum_limit = bignum_low + length + length;
  2011.     }
  2012. }                /* grow_bignum(); */
  2013.  
  2014. /*
  2015.  *            float_cons()
  2016.  *
  2017.  * CONStruct some more frag chars of .floats .ffloats etc.
  2018.  * Makes 0 or more new frags.
  2019.  * If need_pass_2 == 1, no frags are emitted.
  2020.  * This understands only floating literals, not expressions. Sorry.
  2021.  *
  2022.  * A floating constant is defined by atof_generic(), except it is preceded
  2023.  * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
  2024.  * reading, I decided to be incompatible. This always tries to give you
  2025.  * rounded bits to the precision of the pseudo-op. Former AS did premature
  2026.  * truncatation, restored noisy bits instead of trailing 0s AND gave you
  2027.  * a choice of 2 flavours of noise according to which of 2 floating-point
  2028.  * scanners you directed AS to use.
  2029.  *
  2030.  * In:    input_line_pointer->whitespace before, or '0' of flonum.
  2031.  *
  2032.  */
  2033.  
  2034. void                /* JF was static, but can't be if VAX.C is goning to use it */
  2035. float_cons (float_type)        /* Worker to do .float etc statements. */
  2036.      /* Clobbers input_line-pointer, checks end-of-line. */
  2037.      register int float_type;    /* 'f':.ffloat ... 'F':.float ... */
  2038. {
  2039.   register char *p;
  2040.   register char c;
  2041.   int length;            /* Number of chars in an object. */
  2042.   register char *err;        /* Error from scanning floating literal. */
  2043.   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
  2044.  
  2045.   /*
  2046.    * The following awkward logic is to parse ZERO or more strings,
  2047.    * comma seperated. Recall an expression includes its leading &
  2048.    * trailing blanks. We fake a leading ',' if there is (supposed to
  2049.    * be) a 1st expression, and keep demanding 1 expression for each ','.
  2050.    */
  2051.   if (is_it_end_of_statement ())
  2052.     {
  2053.       c = 0;            /* Skip loop. */
  2054.       ++input_line_pointer;    /*->past termintor. */
  2055.     }
  2056.   else
  2057.     {
  2058.       c = ',';            /* Do loop. */
  2059.     }
  2060.   while (c == ',')
  2061.     {
  2062.       /* input_line_pointer->1st char of a flonum (we hope!). */
  2063.       SKIP_WHITESPACE ();
  2064.       /* Skip any 0{letter} that may be present. Don't even check if the
  2065.        * letter is legal. Someone may invent a "z" format and this routine
  2066.        * has no use for such information. Lusers beware: you get
  2067.        * diagnostics if your input is ill-conditioned.
  2068.        */
  2069.  
  2070.       if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
  2071.     input_line_pointer += 2;
  2072.  
  2073.       err = md_atof (float_type, temp, &length);
  2074.       know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
  2075.       know (length > 0);
  2076.       if (err && *err)
  2077.     {
  2078.       as_bad ("Bad floating literal: %s", err);
  2079.       ignore_rest_of_line ();
  2080.       /* Input_line_pointer->just after end-of-line. */
  2081.       c = 0;        /* Break out of loop. */
  2082.     }
  2083.       else
  2084.     {
  2085.       if (!need_pass_2)
  2086.         {
  2087.           p = frag_more (length);
  2088.           bcopy (temp, p, length);
  2089.         }
  2090.       SKIP_WHITESPACE ();
  2091.       c = *input_line_pointer++;
  2092.       /* C contains 1st non-white character after number. */
  2093.       /* input_line_pointer->just after terminator (c). */
  2094.     }
  2095.     }
  2096.   --input_line_pointer;        /*->terminator (is not ','). */
  2097.   demand_empty_rest_of_line ();
  2098. }                /* float_cons() */
  2099.  
  2100. /*
  2101.  *            stringer()
  2102.  *
  2103.  * We read 0 or more ',' seperated, double-quoted strings.
  2104.  *
  2105.  * Caller should have checked need_pass_2 is FALSE because we don't check it.
  2106.  */
  2107.  
  2108.  
  2109. void 
  2110. stringer (append_zero)        /* Worker to do .ascii etc statements. */
  2111.      /* Checks end-of-line. */
  2112.      register int append_zero;    /* 0: don't append '\0', else 1 */
  2113. {
  2114.   register unsigned int c;
  2115.  
  2116.   /*
  2117.    * The following awkward logic is to parse ZERO or more strings,
  2118.    * comma seperated. Recall a string expression includes spaces
  2119.    * before the opening '\"' and spaces after the closing '\"'.
  2120.    * We fake a leading ',' if there is (supposed to be)
  2121.    * a 1st, expression. We keep demanding expressions for each
  2122.    * ','.
  2123.    */
  2124.   if (is_it_end_of_statement ())
  2125.     {
  2126.       c = 0;            /* Skip loop. */
  2127.       ++input_line_pointer;    /* Compensate for end of loop. */
  2128.     }
  2129.   else
  2130.     {
  2131.       c = ',';            /* Do loop. */
  2132.     }
  2133.   while (c == ',' || c == '<' || c == '"')
  2134.     {
  2135.       SKIP_WHITESPACE ();
  2136.       switch (*input_line_pointer)
  2137.     {
  2138.     case '\"':
  2139.       ++input_line_pointer;    /*->1st char of string. */
  2140.       while (is_a_char (c = next_char_of_string ()))
  2141.         {
  2142.           FRAG_APPEND_1_CHAR (c);
  2143.         }
  2144.       if (append_zero)
  2145.         {
  2146.           FRAG_APPEND_1_CHAR (0);
  2147.         }
  2148.       know (input_line_pointer[-1] == '\"');
  2149.       break;
  2150.     case '<':
  2151.       input_line_pointer++;
  2152.       c = get_single_number ();
  2153.       FRAG_APPEND_1_CHAR (c);
  2154.       if (*input_line_pointer != '>')
  2155.         {
  2156.           as_bad ("Expected <nn>");
  2157.         }
  2158.       input_line_pointer++;
  2159.       break;
  2160.     case ',':
  2161.       input_line_pointer++;
  2162.       break;
  2163.     }
  2164.       SKIP_WHITESPACE ();
  2165.       c = *input_line_pointer;
  2166.     }
  2167.  
  2168.   demand_empty_rest_of_line ();
  2169. }                /* stringer() */
  2170.  
  2171. /* FIXME-SOMEDAY: I had trouble here on characters with the
  2172.     high bits set.  We'll probably also have trouble with
  2173.     multibyte chars, wide chars, etc.  Also be careful about
  2174.     returning values bigger than 1 byte.  xoxorich. */
  2175.  
  2176. unsigned int 
  2177. next_char_of_string ()
  2178. {
  2179.   register unsigned int c;
  2180.  
  2181.   c = *input_line_pointer++ & CHAR_MASK;
  2182.   switch (c)
  2183.     {
  2184.     case '\"':
  2185.       c = NOT_A_CHAR;
  2186.       break;
  2187.  
  2188.     case '\\':
  2189.       switch (c = *input_line_pointer++)
  2190.     {
  2191.     case 'b':
  2192.       c = '\b';
  2193.       break;
  2194.  
  2195.     case 'f':
  2196.       c = '\f';
  2197.       break;
  2198.  
  2199.     case 'n':
  2200.       c = '\n';
  2201.       break;
  2202.  
  2203.     case 'r':
  2204.       c = '\r';
  2205.       break;
  2206.  
  2207.     case 't':
  2208.       c = '\t';
  2209.       break;
  2210.  
  2211. #ifdef BACKSLASH_V
  2212.     case 'v':
  2213.       c = '\013';
  2214.       break;
  2215. #endif
  2216.  
  2217.     case '\\':
  2218.     case '"':
  2219.       break;        /* As itself. */
  2220.  
  2221.     case '0':
  2222.     case '1':
  2223.     case '2':
  2224.     case '3':
  2225.     case '4':
  2226.     case '5':
  2227.     case '6':
  2228.     case '7':
  2229.     case '8':
  2230.     case '9':
  2231.       {
  2232.         long number;
  2233.  
  2234.         for (number = 0; isdigit (c); c = *input_line_pointer++)
  2235.           {
  2236.         number = number * 8 + c - '0';
  2237.           }
  2238.         c = number & 0xff;
  2239.       }
  2240.       --input_line_pointer;
  2241.       break;
  2242.  
  2243.     case '\n':
  2244.       /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
  2245.       as_warn ("Unterminated string: Newline inserted.");
  2246.       c = '\n';
  2247.       break;
  2248.  
  2249.     default:
  2250.  
  2251. #ifdef ONLY_STANDARD_ESCAPES
  2252.       as_bad ("Bad escaped character in string, '?' assumed");
  2253.       c = '?';
  2254. #endif /* ONLY_STANDARD_ESCAPES */
  2255.  
  2256.       break;
  2257.     }            /* switch on escaped char */
  2258.       break;
  2259.  
  2260.     default:
  2261.       break;
  2262.     }                /* switch on char */
  2263.   return (c);
  2264. }                /* next_char_of_string() */
  2265.  
  2266. static segT
  2267. get_segmented_expression (expP)
  2268.      register expressionS *expP;
  2269. {
  2270.   register segT retval;
  2271.  
  2272.   retval = expression (expP);
  2273.   if (retval == pass1_section
  2274.       || retval == absent_section
  2275.       || retval == big_section)
  2276.     {
  2277.       as_bad ("Expected address expression: absolute 0 assumed");
  2278.       retval = expP->X_seg = absolute_section;
  2279.       expP->X_add_number = 0;
  2280.       expP->X_add_symbol = expP->X_subtract_symbol = 0;
  2281.     }
  2282.   return (retval);        /* SEG_ ABSOLUTE,UNKNOWN,DATA,TEXT,BSS */
  2283. }
  2284.  
  2285. static segT 
  2286. get_known_segmented_expression (expP)
  2287.      register expressionS *expP;
  2288. {
  2289.   register segT retval;
  2290.   register CONST char *name1;
  2291.   register CONST char *name2;
  2292.  
  2293.   if ((retval = get_segmented_expression (expP)) == undefined_section)
  2294.     {
  2295.       name1 = expP->X_add_symbol ? S_GET_NAME (expP->X_add_symbol) : "";
  2296.       name2 = expP->X_subtract_symbol ?
  2297.     S_GET_NAME (expP->X_subtract_symbol) :
  2298.     "";
  2299.       if (name1 && name2)
  2300.     {
  2301.       as_warn ("Symbols \"%s\" \"%s\" are undefined: absolute 0 assumed.",
  2302.            name1, name2);
  2303.     }
  2304.       else
  2305.     {
  2306.       as_warn ("Symbol \"%s\" undefined: absolute 0 assumed.",
  2307.            name1 ? name1 : name2);
  2308.     }
  2309.       retval = expP->X_seg = absolute_section;
  2310.       expP->X_add_number = 0;
  2311.       expP->X_add_symbol = expP->X_subtract_symbol = NULL;
  2312.     }
  2313.   know (retval == absolute_section
  2314.     || retval == diff_section
  2315.     || SEG_NORMAL (retval));
  2316.   return (retval);
  2317.  
  2318. }                /* get_known_segmented_expression() */
  2319.  
  2320.  
  2321.  
  2322. /* static */ long        /* JF was static, but can't be if the MD pseudos are to use it */
  2323. get_absolute_expression ()
  2324. {
  2325.   expressionS exp;
  2326.   register segT s;
  2327.  
  2328.   if ((s = expression (&exp)) != absolute_section)
  2329.     {
  2330.       if (s != absent_section)
  2331.     {
  2332.       as_bad ("Bad Absolute Expression, absolute 0 assumed.");
  2333.     }
  2334.       exp.X_add_number = 0;
  2335.     }
  2336.   return (exp.X_add_number);
  2337. }
  2338.  
  2339. char                /* return terminator */
  2340. get_absolute_expression_and_terminator (val_pointer)
  2341.      long *val_pointer;        /* return value of expression */
  2342. {
  2343.   *val_pointer = get_absolute_expression ();
  2344.   return (*input_line_pointer++);
  2345. }
  2346.  
  2347. /*
  2348.  *            demand_copy_C_string()
  2349.  *
  2350.  * Like demand_copy_string, but return NULL if the string contains any '\0's.
  2351.  * Give a warning if that happens.
  2352.  */
  2353. char *
  2354. demand_copy_C_string (len_pointer)
  2355.      int *len_pointer;
  2356. {
  2357.   register char *s;
  2358.  
  2359.   if ((s = demand_copy_string (len_pointer)) != 0)
  2360.     {
  2361.       register int len;
  2362.  
  2363.       for (len = *len_pointer;
  2364.        len > 0;
  2365.        len--)
  2366.     {
  2367.       if (*s == 0)
  2368.         {
  2369.           s = 0;
  2370.           len = 1;
  2371.           *len_pointer = 0;
  2372.           as_bad ("This string may not contain \'\\0\'");
  2373.         }
  2374.     }
  2375.     }
  2376.   return (s);
  2377. }
  2378.  
  2379. /*
  2380.  *            demand_copy_string()
  2381.  *
  2382.  * Demand string, but return a safe (=private) copy of the string.
  2383.  * Return NULL if we can't read a string here.
  2384.  */
  2385. static char *
  2386. demand_copy_string (lenP)
  2387.      int *lenP;
  2388. {
  2389.   register unsigned int c;
  2390.   register int len;
  2391.   char *retval;
  2392.  
  2393.   len = 0;
  2394.   SKIP_WHITESPACE ();
  2395.   if (*input_line_pointer == '\"')
  2396.     {
  2397.       input_line_pointer++;    /* Skip opening quote. */
  2398.  
  2399.       while (is_a_char (c = next_char_of_string ()))
  2400.     {
  2401.       obstack_1grow (¬es, c);
  2402.       len++;
  2403.     }
  2404.       /* JF this next line is so demand_copy_C_string will return a null
  2405.            termanated string. */
  2406.       obstack_1grow (¬es, '\0');
  2407.       retval = obstack_finish (¬es);
  2408.     }
  2409.   else
  2410.     {
  2411.       as_warn ("Missing string");
  2412.       retval = NULL;
  2413.       ignore_rest_of_line ();
  2414.     }
  2415.   *lenP = len;
  2416.   return (retval);
  2417. }                /* demand_copy_string() */
  2418.  
  2419. /*
  2420.  *        is_it_end_of_statement()
  2421.  *
  2422.  * In:    Input_line_pointer->next character.
  2423.  *
  2424.  * Do:    Skip input_line_pointer over all whitespace.
  2425.  *
  2426.  * Out:    1 if input_line_pointer->end-of-line.
  2427. */
  2428. int 
  2429. is_it_end_of_statement ()
  2430. {
  2431.   SKIP_WHITESPACE ();
  2432.   return (is_end_of_line[*input_line_pointer]);
  2433. }                /* is_it_end_of_statement() */
  2434.  
  2435. void 
  2436. equals (sym_name)
  2437.      char *sym_name;
  2438. {
  2439.   register symbolS *symbolP;    /* symbol we are working with */
  2440.  
  2441.   input_line_pointer++;
  2442.   if (*input_line_pointer == '=')
  2443.     input_line_pointer++;
  2444.  
  2445.   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
  2446.     input_line_pointer++;
  2447.  
  2448.   if (sym_name[0] == '.' && sym_name[1] == '\0')
  2449.     {
  2450.       /* Turn '. = mumble' into a .org mumble */
  2451.       register segT segment;
  2452.       expressionS exp;
  2453.       register char *p;
  2454.  
  2455.       segment = get_known_segmented_expression (&exp);
  2456.       if (!need_pass_2)
  2457.     {
  2458.       if (segment != now_seg && segment != absolute_section)
  2459.         as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
  2460.              segment_name (segment),
  2461.              segment_name (now_seg));
  2462.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
  2463.             exp.X_add_number, (char *) 0);
  2464.       *p = 0;
  2465.     }            /* if (ok to make frag) */
  2466.     }
  2467.   else
  2468.     {
  2469.       symbolP = symbol_find_or_make (sym_name);
  2470.       pseudo_set (symbolP);
  2471.     }
  2472. }                /* equals() */
  2473.  
  2474. /* .include -- include a file at this point. */
  2475.  
  2476. /* ARGSUSED */
  2477. void 
  2478. s_include (arg)
  2479.      int arg;
  2480. {
  2481.   char *newbuf;
  2482.   char *filename;
  2483.   int i;
  2484.   FILE *try;
  2485.   char *path;
  2486.  
  2487.   filename = demand_copy_string (&i);
  2488.   demand_empty_rest_of_line ();
  2489.   path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
  2490.   for (i = 0; i < include_dir_count; i++)
  2491.     {
  2492.       strcpy (path, include_dirs[i]);
  2493.       strcat (path, "/");
  2494.       strcat (path, filename);
  2495.       if (0 != (try = fopen (path, "r")))
  2496.     {
  2497.       fclose (try);
  2498.       goto gotit;
  2499.     }
  2500.     }
  2501.   free (path);
  2502.   path = filename;
  2503. gotit:
  2504.   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY. */
  2505.   newbuf = input_scrub_include_file (path, input_line_pointer);
  2506.   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
  2507. }                /* s_include() */
  2508.  
  2509. void 
  2510. add_include_dir (path)
  2511.      char *path;
  2512. {
  2513.   int i;
  2514.  
  2515.   if (include_dir_count == 0)
  2516.     {
  2517.       include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
  2518.       include_dirs[0] = ".";    /* Current dir */
  2519.       include_dir_count = 2;
  2520.     }
  2521.   else
  2522.     {
  2523.       include_dir_count++;
  2524.       include_dirs = (char **) realloc (include_dirs,
  2525.                 include_dir_count * sizeof (*include_dirs));
  2526.     }
  2527.  
  2528.   include_dirs[include_dir_count - 1] = path;    /* New one */
  2529.  
  2530.   i = strlen (path);
  2531.   if (i > include_dir_maxlen)
  2532.     include_dir_maxlen = i;
  2533. }                /* add_include_dir() */
  2534.  
  2535. void 
  2536. s_ignore (arg)
  2537.      int arg;
  2538. {
  2539.   while (!is_end_of_line[*input_line_pointer])
  2540.     {
  2541.       ++input_line_pointer;
  2542.     }
  2543.   ++input_line_pointer;
  2544.  
  2545.   return;
  2546. }                /* s_ignore() */
  2547.  
  2548. /* end of read.c */
  2549.